package org.example.everyday;

import java.util.HashSet;
import java.util.Set;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2022/6/16 9:17
 */
public class Lc532 {
    public static void main(String[] args) {
        Lc532 lc532 = new Lc532();
        int[] nums = {3, 1, 4, 1, 5};
        int k = 2;
        int res = lc532.findPairs(nums,k);
        System.out.println(res);

    }

    public int findPairs(int[] nums, int k) {
        Set<Integer> visited = new HashSet<Integer>();
        Set<Integer> res = new HashSet<Integer>();
        for (int num : nums){
            if(visited.contains(num - k)){
                res.add(num - k);
            }
            if(visited.contains(num + k)){
                res.add(num);
            }
            visited.add(num);
        }
        return res.size();

    }
}
